<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>思维导图演示</title>
    <style>
        #canvas-container {
            position: relative;
            width: 100%;
            height: 100vh;
            overflow: hidden;
        }
        #mindmap {
            width: 100%;
            height: 100%;
        }
        .toolbar {
            position: fixed;
            top: 20px;
            left: 20px;
            z-index: 1000;
            background: white;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
        }
        .toolbar button {
            margin: 5px;
            padding: 5px 10px;
            border: none;
            border-radius: 3px;
            background: #4CAF50;
            color: white;
            cursor: pointer;
        }
        .toolbar button:hover {
            background: #45a049;
        }
        #node-info {
            position: fixed;
            bottom: 20px;
            left: 20px;
            background: white;
            padding: 10px;
            border-radius: 5px;
            box-shadow: 0 2px 5px rgba(0,0,0,0.2);
            max-width: 300px;
        }
    </style>
</head>
<body>
    <div class="toolbar">
        <button id="add-node">添加节点</button>
        <button id="delete-node">删除节点</button>
        <button id="copy-node">复制节点</button>
        <button id="reset-view">重置视图</button>
    </div>
    
    <div id="node-info">
        <h3>节点信息</h3>
        <p>当前选中: 无</p>
        <p>最近操作: 无</p>
    </div>

    <div id="canvas-container">
        <canvas id="mindmap"></canvas>
    </div>

    <script src="mindmap.js"></script>
    <script>
        document.addEventListener('DOMContentLoaded', () => {
            // 创建思维导图实例，并配置事件回调
            const mindmap = new MindMap('mindmap', {
                // 节点选择事件
                onNodeSelect: (node) => {
                    const nodeInfo = document.getElementById('node-info');
                    if (node) {
                        nodeInfo.querySelector('p:first-of-type').textContent = `当前选中: ${node.text}`;
                    } else {
                        nodeInfo.querySelector('p:first-of-type').textContent = '当前选中: 无';
                    }
                },
                
                // 节点激活事件
                onNodeActivate: (node) => {
                    console.log('节点被激活:', node.text);
                },
                
                // 节点编辑事件
                onNodeEdit: (node, oldText, newText) => {
                    const nodeInfo = document.getElementById('node-info');
                    nodeInfo.querySelector('p:last-of-type').textContent = 
                        `最近操作: 编辑节点 "${oldText}" -> "${newText}"`;
                },
                
                // 节点删除事件
                onNodeDelete: (node) => {
                    const nodeInfo = document.getElementById('node-info');
                    nodeInfo.querySelector('p:last-of-type').textContent = 
                        `最近操作: 删除节点 "${node.text}"`;
                },
                
                // 节点添加事件
                onNodeAdd: (node, parentNode) => {
                    const nodeInfo = document.getElementById('node-info');
                    nodeInfo.querySelector('p:last-of-type').textContent = 
                        `最近操作: 添加节点 "${node.text}" 到 "${parentNode.text}"`;
                },
                
                // 节点折叠事件
                onNodeCollapse: (node) => {
                    const nodeInfo = document.getElementById('node-info');
                    nodeInfo.querySelector('p:last-of-type').textContent = 
                        `最近操作: 折叠节点 "${node.text}"`;
                },
                
                // 节点展开事件
                onNodeExpand: (node) => {
                    const nodeInfo = document.getElementById('node-info');
                    nodeInfo.querySelector('p:last-of-type').textContent = 
                        `最近操作: 展开节点 "${node.text}"`;
                }
            });

            // 将mindmap实例暴露给window对象
            window.mindmapInstance = mindmap;
        });
    </script>
</body>
</html>